<template>
  <el-container class="layout-container">
    <!-- 顶部导航栏 -->
    <el-header height="60px" class="header">
      <div class="logo">
        <img src="../assets/vue.svg" alt="Logo" class="logo-img">
        <span class="logo-text">小窝物业管理系统</span>
      </div>
      <div class="header-right">
        <el-dropdown>
          <span class="user-info">
            <el-avatar :size="32" :src="userAvatar" />
            <span class="username">{{ username }}</span>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
                          <el-dropdown-item>个人信息</el-dropdown-item>
            <el-dropdown-item>修改密码</el-dropdown-item>
            <el-dropdown-item divided @click="handleLogout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>

    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px" class="aside">
        <el-menu
          :default-active="activeMenu"
          class="menu"
          :collapse="isCollapse"
          router
          @select="handleSelect"
        >
          <el-menu-item index="/index">
            <el-icon><House /></el-icon>
            <template #title>首页</template>
          </el-menu-item>
          
          <el-sub-menu index="2">
            <template #title>
              <el-icon><Location /></el-icon>
              <span>巡更管理</span>
            </template>
            <el-menu-item index="/man">巡更管理</el-menu-item>
            <el-menu-item index="/task">巡更任务</el-menu-item>
            <el-menu-item index="/map">巡更地图</el-menu-item>
            <el-menu-item index="/record">巡更记录</el-menu-item>
            <el-menu-item index="/point">巡更点位</el-menu-item>
            <el-menu-item index="/category">巡更分类</el-menu-item>
            <el-menu-item index="/route">巡更路线</el-menu-item>
            <el-menu-item index="/plan">巡更计划</el-menu-item>
            <el-menu-item index="/analyze">AI分析</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="3">
            <template #title>
              <el-icon><Van /></el-icon>
              <span>车辆管理</span>
            </template>
            <el-menu-item index="/parking">停车场管理</el-menu-item>
            <el-menu-item index="/vehicle-list">车辆列表</el-menu-item>
            <el-menu-item index="/parking-record">停车记录</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="4">
            <template #title>
              <el-icon><Tools /></el-icon>
              <span>报修审批</span>
            </template>
            <el-menu-item index="/repair">审批</el-menu-item>
<!--            <el-menu-item index="4-2">维修记录</el-menu-item>-->
          </el-sub-menu>

          <el-sub-menu index="6">
            <template #title>
              <el-icon><Odometer /></el-icon>
              <span>抄表管理</span>
            </template>
            <el-menu-item index="/meter-reading">抄表记录</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="10">
            <template #title>
              <el-icon><Van /></el-icon>
              <span>角色管理</span>
            </template>
            <el-menu-item index="/faceInfo">业主录入</el-menu-item>
            <el-menu-item index="/faceopencv">人脸开锁</el-menu-item>
            <el-menu-item index="/parking-record">停车记录</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="7">
            <template #title>
              <el-icon><Van /></el-icon>
              <span>监控管理</span>
            </template>
            <el-menu-item index="/Monitor">小窝监控</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="5">
            <template #title>
              <el-icon><Cpu /></el-icon>
              <span>AI智能</span>
            </template>
            <el-menu-item index="/aics">智能客服</el-menu-item>
            <el-menu-item index="/knowledge-management">知识库管理</el-menu-item>
            <el-menu-item index="/sensitiveWord-management">敏感词管理</el-menu-item>
          </el-sub-menu>



          <!-- 新增：基础功能管理菜单，风格与其他菜单一致 -->
          <el-sub-menu index="8">
            <template #title>
              <el-icon><Odometer /></el-icon>
              <span>基础管理</span>
            </template>
            <el-menu-item index="/community-management">小区管理</el-menu-item>
            <el-menu-item index="/building-management">楼宇管理</el-menu-item>
            <el-menu-item index="/light-management">灯光管理</el-menu-item>
          </el-sub-menu>

          <el-menu-item index="/news">
            <el-icon><Odometer /></el-icon>
            <template #title>新闻资讯</template>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 主要内容区 -->
      <el-main class="main">
        <router-view></router-view>

      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import {House, Location, Van, Tools, Setting, Cpu, Odometer} from '@element-plus/icons-vue'

const router = useRouter()

// 用户信息
const username = ref('管理员')
const userAvatar = ref('https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png')

// 菜单状态
const isCollapse = ref(false)
const activeMenu = ref('1')

// 菜单选择处理
const handleSelect = (index) => {
  activeMenu.value = index
}

// 退出登录
const handleLogout = () => {
  ElMessageBox.confirm('确定要退出登录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    // 清除token
    sessionStorage.removeItem('token')
    ElMessage.success('退出登录成功')
    // 跳转到登录页
    router.push('/login')
  }).catch(() => {
    // 用户取消退出
  })
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
  width: 98vw;
}

.header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.logo {
  display: flex;
  align-items: center;
}

.logo-img {
  height: 32px;
  margin-right: 10px;
}

.logo-text {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.username {
  margin-left: 8px;
  font-size: 14px;
  color: #333;
}

.aside {
  background-color: #fff;
  border-right: 1px solid #e6e6e6;
}

.menu {
  height: 100%;
  border-right: none;
}

.main {
  background-color: #f5f7fa;
  padding: 20px;
}

:deep(.el-menu-item.is-active) {
  background-color: #ecf5ff;
}
</style> 